import Mock from 'mockjs2'
import {
	builder,
	getBody
} from '../util'

const username = ['admin']
// 强硬要求 ant.design 相同密码
const password = ['123456'] // admin, ant.design
const login = (options) => {
	const body = getBody(options)
	if (!username.includes(body.userName) || !password.includes(body.password)) {
		return builder({
			isLogin: true
		}, '账户或密码错误', false)
	}

	return builder({
		'id': Mock.mock('@guid'),
		'name': Mock.mock('@name'),
		'username': 'admin',
		'password': '',
		'avatar': 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
		'status': 1,
		'telephone': '',
		'lastLoginIp': '27.154.74.117',
		'lastLoginTime': 1534837621348,
		'creatorId': 'admin',
		'createTime': 1497160610259,
		'deleted': 0,
		'roleId': 'admin',
		'lang': 'zh-CN',
		'token': '4291d7da9005377ec9aec4a71ea837f'
	}, '', true, {
		'Custom-Header': Mock.mock('@guid')
	})
}

const logout = () => {
	return builder({}, '[测试接口] 注销成功')
}

const smsCaptcha = () => {
	return builder({
		captcha: Mock.mock('@integer(10000, 99999)')
	})
}

const twofactor = () => {
	return builder({
		stepCode: Mock.mock('@integer(0, 1)')
	})
}
Mock.mock(/\/passport\/login/, 'post', login)
